<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Gets the primary language for the input locale</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="locale.getkeywords.html">« Locale::getKeywords</a></li>
      <li style="float: right;"><a href="locale.getregion.html">Locale::getRegion »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.locale.html">Locale</a></li>
    <li>Gets the primary language for the input locale</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="locale.getprimarylanguage" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Locale::getPrimaryLanguage</h1>
  <h1 class="refname">locale_get_primary_language</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Locale::getPrimaryLanguage</span> -- <span class="refname">locale_get_primary_language</span> &mdash; <span class="dc-title">Gets the primary language for the input locale</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-locale.getprimarylanguage-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>Locale::getPrimaryLanguage</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>): <span class="type"><span class="type">?</span><span class="type">string</span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>locale_get_primary_language</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>): <span class="type"><span class="type">?</span><span class="type">string</span></span></div>

  <p class="para rdfs-comment">
   Gets the primary language for the input locale
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-locale.getprimarylanguage-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">locale</code></dt>

     <dd>

      <p class="para">
       The locale to extract the primary language code from
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-locale.getprimarylanguage-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The language code associated with the language.
  </p>
  <p class="para">当 <code class="parameter">locale</code> 的长度超过 <strong><code>INTL_MAX_LOCALE_LEN</code></strong> 时返回 <strong><code>null</code></strong>。</p>
 </div>


 <div class="refsect1 examples" id="refsect1-locale.getprimarylanguage-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2350">
   <p><strong>示例 #1 <span class="function"><strong>locale_get_primary_language()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">locale_get_primary_language</span><span style="color: #007700">(</span><span style="color: #DD0000">'zh-Hant'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-2351">
   <p><strong>示例 #2 OO example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">Locale</span><span style="color: #007700">::</span><span style="color: #0000BB">getPrimaryLanguage</span><span style="color: #007700">(</span><span style="color: #DD0000">'zh-Hant'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
zh
</pre></div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-locale.getprimarylanguage-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="locale.getscript.html" class="function" rel="rdfs-seeAlso">locale_get_script()</a> - Gets the script for the input locale</span></li>
    <li class="member"><span class="function"><a href="locale.getregion.html" class="function" rel="rdfs-seeAlso">locale_get_region()</a> - Gets the region for the input locale</span></li>
    <li class="member"><span class="function"><a href="locale.getallvariants.html" class="function" rel="rdfs-seeAlso">locale_get_all_variants()</a> - Gets the variants for the input locale</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>